
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户名密码登录</title>
    <link rel="shortcut icon" href="assets/img/favicon.ico">
</head>
<style>
    body{ background:url("../imgs/bj.jpg");
        background-repeat: no-repeat;
        background-size: cover;}
    #main{
        margin:15% auto;
        width:300px;
        height:150px;
        font-size: 14px;
        color:black;
        font-weight: 500;
    }
    .srk{
        display: block;
        height: 16px;
        width: 328px;
        padding: 11px 10px;
        margin-right: 10px;
        border: 1px solid #ddd;
        font-size: 14px;
        color: #666;
    }
    #button_dr{
        background-color:#3F89EC;
        width:300px;
        height:50px;
        color:#FFF;
        font-size: 16px;
        font-weight: 700;
        border:0;
        position:relative;
        left:20px;
    }
    #button_dr:hover {
        background-color:#4490F7
    }

</style>
<script type="text/javascript">
    function dr(){
        var inputname = form.inputname.value;
        var password = form.password.value;
        if(inputname == ""){
            alert("请输入用户名");
            return;
        }
        if(password == ""){
            alert("请输入密码");
            return;
        }
        alert("登入成功");
    }
</script>
<body>
<div id="main">
    <h1 align="center">用户名密码登录</h1>
    用户类型：
    <br>
    <select name="lx">
        <option value="1">普通用户</option>
        <option value="2">管理员用户</option>
    </select>
    <form name="form" method="post" action="drym.php">
        用户名：
        <input class="srk" id="name" name="inputname" type="text">
        <br>
        密码：
        <input class="srk" id="button-dr" name="password" type="password">
        <br>
        <input id="button_dr" name="button_dr" type="submit" value="登入" onClick="">
    </form>
</div>
<footer style="text-align:center">
    <p>Copyright © 2019&nbsp;FirPE Project All Rights Reserved. </p>
</footer>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
    if(isset($_POST['button_dr'])){
        $name = $_POST['inputname'];
        $password = $_POST['password'];
        if($name == ""){
            echo "<script>alert('请输入用户名')</script>";
            exit();
        }
        if($password == ""){
            echo "<script>alert('请输入密码')</script>";
            exit();
        }
        if($name == "admin" and $password == "123456"){
            $name = "管理员-" . $name;
        }
        session_start();
        $user = $_SESSION['username'];
        $userpassword = $_SESSION['userpassword'];
        if($name  == $user  and $password == $userpassword){
            echo "<script>alert('登入成功')</script>";
            session_start();
            $_SESSION['username']=$name;
//跳转到主页面


            echo "<script>window.location.href = 'yhdrcg.php'</script>";

        }else{
            echo "<script>alert('登入失败')</script>";
            exit();
        }
    }
}
?>
